<?php

class RecordAction extends CommonAction
{
	
	public function isPrize(){
		$prize = $this->getPrize();
		if($prize['satisfy'] || $prize['lotto'] || $prize['auction'] ){
			$result = 1;
		}else{
			$result = -1;
		}
		$data['status'] = $result;
		die(json_encode($data));
	}
	
	
	public function getPrize() {
		$u_id = $this->Core->User->u_id;
		$prize['satisfy'] = $this->prizeListForUser($u_id, 'satisfy');
		$prize['lotto'] = $this->prizeListForUser($u_id, 'lotto');
		$prize['auction'] = $this->prizeListForUser($u_id, 'auction');
		return $prize;
	}
	
	private function prizeListForUser($u_id, $type){
		$_model = M('RecordPrize');
		$_con['u_id'] = $u_id;
		$_con['rep_type'] = $type;
		$join = ' ws_prize_store on ws_prize_store.prst_id=ws_record_prize.prst_id ';
		$list = $_model->join($join)->where($_con)->select();
		return $list;
		
	}
	
	public function get($type, $_where, $_limit=10){
		$_model = M('Record'.ucfirst($type));
		$pk = $_model->getPk();
		$_order = $pk.' desc';
		$list = $_model->where($_where)->limit($_limit)->order($_order)->select();
		return $list;
	}
	
	# 记录日志
	public function onAdd($type, $params){
		D('Record')->onAdd($type, $params);
	}
	
	// 看视频获取金币
	public function mediaForGold(){
		$key = $this->checkKey();
		$type = 'gold';
		$params['u_id'] = $this->Core->User->u_id;
		$params['reg_gold'] = 1;
		$params['reg_description'] = '观看视频'.$key.',金币+1';
		$params['reg_key'] = $key;
		$this->checkRepeat($params['u_id'], $params['reg_key']);
		$this->onAdd($type, $params);
	}
	
	private function checkRepeat($u_id, $key){
		$_con['u_id'] = $u_id;
		$_con['reg_key'] = $key;
		$reg = M('RecardGold')->where($_con)->find();
		return $reg ? -2 : 1 ;
	}
	
	private function checkKey(){
		
		
	}
	
	
	
	

}













?>